//
//  LXRequstDetailHeaderView.m
//  TuDianEducation
//
//  Created by lixinkeji on 2020/6/29.
//  Copyright © 2020 zhangbenchao. All rights reserved.
//


#import "LXRequstDetailHeaderView.h"
#import "LXOrderMessageValueItemView.h"
#import "LXTitleImgView.h"
#import "LXSaveUserInforTool.h"
#import "LXUserInforModel.h"
#import "BkMessageOrderView.h"

@interface LXRequstDetailHeaderView()
@property (nonatomic,strong) UIView *headerMessageView;
@property (nonatomic,strong) UILabel *headerMessageLabel;
@property (nonatomic,strong) UIView *goodsMessageView;
@property (nonatomic,strong) UIImageView *headerImgView;
@property (nonatomic,strong) UILabel *bkNameLabel;
@property (nonatomic,strong) UILabel *moneyLabel;
@property (nonatomic,strong) UILabel *sevendaysLabel;
@property (nonatomic,strong) UILabel *amountLabel;
@property (nonatomic,strong) LXOrderMessageValueItemView *goodsAllPriceView;
@property (nonatomic,strong) LXOrderMessageValueItemView *yunfeiView;
@property (nonatomic,strong) LXOrderMessageValueItemView *youhui;
@property (nonatomic,strong) LXOrderMessageValueItemView *orderAllPriceView;

@property (nonatomic,strong) UIView *addressView;
@property (nonatomic,strong) UIImageView *addressImg;
@property (nonatomic,strong) UILabel *detailAddressLabel;
@property (nonatomic,strong) UIImageView *gotoImg;
@property (nonatomic,strong) UILabel *userNameLabel;



@property (nonatomic,strong) NSArray *messageArray;
@property (nonatomic,strong) NSMutableArray *uiMessageArray;

@property (nonatomic,assign) CGFloat topOff;

@end

@implementation LXRequstDetailHeaderView

-(instancetype)init
{
    if (self = [super init])
    {
        [self viewConfig];
    }
    return self;
}
-(void)viewConfig{
    self.frame = CGRectMake(0, 0, TSScreenWidth, TSScaleW(100));
    self.backgroundColor = kSubBacColor;
    [self addSubview:self.headerMessageView];
    [self.headerMessageView addSubview:self.headerMessageLabel];
    [self addSubview:self.addressView];
    [self.addressView addSubview:self.addressImg];
    [self.addressView addSubview:self.detailAddressLabel];
    [self.addressView addSubview:self.userNameLabel];
    
    [self.addressView addSubview:self.gotoImg];
    [self addSubview:self.goodsMessageView];
    
    
   
   
}
-(UIView *)headerMessageView{
    if (!_headerMessageView) {
        _headerMessageView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, TSScreenWidth, TSScaleW(40))];
       
    }
    return _headerMessageView;
}
-(UILabel *)headerMessageLabel
{
    if (!_headerMessageLabel) {
        _headerMessageLabel = [TSWLTools allocLabel:@"待付款" font:systemBoldFont(20) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(11), 0, TSScreenWidth - TSScaleW(29), _headerMessageView.height) textAlignment:(NSTextAlignmentLeft)];
    }
    return _headerMessageLabel;
}
-(UIView *)addressView{
    if (!_addressView) {
        _addressView = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(12), TSScaleW(10) + _headerMessageView.bottom, TSScaleW(350), TSScaleW(84))];
        _addressView.backgroundColor = kWhiteColor;
        [_addressView setCornerRadius:TSScaleW(10)];
         UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoAddressVc)];
        _addressView.userInteractionEnabled = YES;
        [_addressView addGestureRecognizer:tap];
    }
    return _addressView;
}
-(UIImageView *)addressImg{
    if (!_addressImg) {
        _addressImg = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(10), TSScaleW(36), TSScaleW(12), TSScaleW(12))];
        _addressImg.image = [UIImage imageNamed:@"shouhuodizhi"];
        
    }
    return _addressImg;;
}
-(UILabel *)detailAddressLabel{
    if (!_detailAddressLabel) {
        _detailAddressLabel = [TSWLTools allocLabel:@"河南省郑州市金水区商都世贸中心D座2202室" font:systemFont(TSScaleW(14)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(10) + _addressImg.right,  TSScaleW(27), TSScaleW(300), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
       
        
    }
    return _detailAddressLabel;
}
-(UILabel *)userNameLabel{
    if (!_userNameLabel) {
        _userNameLabel = [TSWLTools allocLabel:@"李帅 134574477441" font:systemFont(TSScaleW(12)) textColor:kGrayTxtColor frame:CGRectMake(TSScaleW(12) + _addressImg.right, _detailAddressLabel.bottom + TSScaleW(8), TSScaleW(300), TSScaleW(12)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _userNameLabel;
}

-(UIImageView *)gotoImg{
    if (!_gotoImg) {
        _gotoImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"chakanquanbu"]];
        _gotoImg.right = _addressView.width - TSScaleW(10);
        _gotoImg.centerY = _addressView.height/2.f;
        _gotoImg.hidden = YES;
    }
    return _gotoImg;
}
-(UIView *)goodsMessageView{
    if (!_goodsMessageView) {
        _goodsMessageView = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(13), TSScaleW(10) + _addressView.bottom, TSScreenWidth - TSScaleW(26), TSScaleW(82))];
        _goodsMessageView.backgroundColor = kWhiteColor;
        _goodsMessageView.cornerRadius = TSScaleW(10);
    }
    return _goodsMessageView;
}
-(UIImageView *)headerImgView{
    if (!_headerImgView) {
        _headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(TSScaleW(15), TSScaleW(23), TSScaleW(47), TSScaleW(63))];
        _headerImgView.backgroundColor = kGrayTxtColor;

    }
    return _headerImgView;
}
-(UILabel *)bkNameLabel{
    if (!_bkNameLabel) {
        _bkNameLabel = [TSWLTools allocLabel:@"初中数学运算大法" font:systemFont(TSScaleW(14)) textColor:kMainTxtColor frame:CGRectMake(_headerImgView.right + TSScaleW(10),  _headerImgView.top + TSScaleW(4), TSScaleW(210), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
        //_bkNameLabel.numberOfLines = 0;
    }
    return _bkNameLabel;
}
-(UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [TSWLTools allocLabel:@"￥999.00" font:systemFont(TSScaleW(12)) textColor:kMainTxtColor frame:CGRectMake(_headerImgView.right + TSScaleW(10), _bkNameLabel.top, TSScaleW(260), TSScaleW(15)) textAlignment:(NSTextAlignmentRight)];
        NSString *string = _moneyLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string.length - 4)];
        _moneyLabel.attributedText = atts;
    }
    return _moneyLabel;
}
-(UILabel *)sevendaysLabel{
    if (!_sevendaysLabel) {
        _sevendaysLabel = [TSWLTools allocLabel:@"7天无理由退换" font:systemFont(10) textColor:UIColorFromRGB(0xD95F35) frame:CGRectMake(_bkNameLabel.left, TSScaleW(9) + _bkNameLabel.bottom, TSScaleW(80), TSScaleW(15)) textAlignment:(NSTextAlignmentCenter)];
        _sevendaysLabel.backgroundColor = UIColorFromRGB(0xFFF1F1);
        _sevendaysLabel.cornerRadius = _sevendaysLabel.height/2.f;
        
    }
    return _sevendaysLabel;
}
-(UILabel *)amountLabel{
    if (!_amountLabel) {
        _amountLabel = [TSWLTools allocLabel:@"x1" font:systemFont(12) textColor:kGrayTxtColor frame:CGRectMake(_moneyLabel.left, TSScaleW(37) + _moneyLabel.bottom, _moneyLabel.width , TSScaleW(12)) textAlignment:(NSTextAlignmentRight)];
    }
    return _amountLabel;
}

- (LXOrderMessageValueItemView *)goodsAllPriceView{
    if (!_goodsAllPriceView) {
        _goodsAllPriceView = [[LXOrderMessageValueItemView alloc]initWithTop:TSScaleW(20) + _topOff titleString:@"商品总价" valueString:@"￥80.00" isRedValue:NO];
        _goodsAllPriceView.titleLabel.textColor = kGrayTxtColor;
        _goodsAllPriceView.titleLabel.font = systemFont(TSScaleW(12));
        _goodsAllPriceView.valueLabel.textColor = kMainTxtColor;
        _goodsAllPriceView.valueLabel.font = systemFont(TSScaleW(12));
        NSString *string = _goodsAllPriceView.valueLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string.length - 4)];
        _goodsAllPriceView.valueLabel.attributedText = atts;
    }
    return _goodsAllPriceView;
}
- (LXOrderMessageValueItemView *)yunfeiView{
    if (!_yunfeiView) {
        _yunfeiView = [[LXOrderMessageValueItemView alloc]initWithTop: _goodsAllPriceView.bottom titleString:@"运费" valueString:@"0.00" isRedValue:NO];
        _yunfeiView.titleLabel.textColor = kGrayTxtColor;
        _yunfeiView.titleLabel.font = systemFont(TSScaleW(12));
        _yunfeiView.valueLabel.textColor = kGrayTxtColor;
        _yunfeiView.valueLabel.font = systemFont(TSScaleW(12));
        NSString *string = _yunfeiView.valueLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(0,  string.length - 3)];
        _yunfeiView.valueLabel.attributedText = atts;
    }
    return _yunfeiView;
}
- (LXOrderMessageValueItemView *)youhui{
    if (!_youhui) {
        _youhui = [[LXOrderMessageValueItemView alloc]initWithTop:_yunfeiView.bottom titleString:@"优惠" valueString:@"暂无优惠" isRedValue:NO];
        _youhui.titleLabel.textColor = kGrayTxtColor;
        _youhui.titleLabel.font = systemFont(TSScaleW(12));
        _youhui.valueLabel.textColor = kGreenColor;
        _youhui.valueLabel.font = systemFont(TSScaleW(12));
        
    }
    return _youhui;
}
- (LXOrderMessageValueItemView *)orderAllPriceView{
    if (!_orderAllPriceView) {
        _orderAllPriceView = [[LXOrderMessageValueItemView alloc]initWithTop:TSScaleW(10) + _youhui.bottom titleString:@"订单总价" valueString:@"￥80.00" isRedValue:YES];
        _orderAllPriceView.titleLabel.textColor = kMainTxtColor;
        _orderAllPriceView.titleLabel.font = systemFont(TSScaleW(12));
        _orderAllPriceView.valueLabel.font = systemFont(TSScaleW(12));
        NSString *string = _orderAllPriceView.valueLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string.length - 4)];
        _orderAllPriceView.valueLabel.attributedText = atts;
    }
    return _orderAllPriceView;
}
-(void)gotoAddressVc{
    !self.gotoAddressBlock?:self.gotoAddressBlock();
}


-(void)setMessageArray:(NSArray *)messageArray{
    _messageArray = messageArray;
    for (UIView *v  in self.uiMessageArray) {
        [v removeFromSuperview];
    }
    [self.uiMessageArray removeAllObjects];
    CGFloat top = TSScaleW(20);
    for (int i = 0; i <self.messageArray.count; i ++) {
        NSDictionary *dataDic = self.messageArray[i];
        BkMessageOrderView *messageView = [[BkMessageOrderView alloc]init];
        messageView.top = top;
        top += messageView.height;
        _topOff = messageView.bottom;
        messageView.dataDic = dataDic;
        [self.goodsMessageView addSubview:messageView];
        [self.uiMessageArray addObject:messageView];
    }
    
    [self.goodsMessageView addSubview:self.goodsAllPriceView];
    [self.goodsMessageView addSubview:self.yunfeiView];
    [self.goodsMessageView addSubview:self.youhui];
    [self.goodsMessageView addSubview:self.orderAllPriceView];
    self.goodsMessageView.height = self.orderAllPriceView.bottom + TSScaleW(5);
    self.height = self.goodsMessageView.bottom + TSScaleW(6);
    
    !self.reloadFrameBlock?:self.reloadFrameBlock();
    
    
}
-(NSMutableArray *)uiMessageArray{
    if (!_uiMessageArray) {
        _uiMessageArray = [NSMutableArray array];
    }
    return _uiMessageArray;
}
-(void)setModel:(LXRequstOrderDetailModel *)model{
    _model = model;
    self.messageArray = _model.ordertailList;
    _goodsAllPriceView.valueLabel.text = [NSString stringWithFormat:@"￥%.2f",_model.goodsprice.doubleValue];
    NSString *string = _goodsAllPriceView.valueLabel.text;
    NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
    [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string.length - 4)];
    _goodsAllPriceView.valueLabel.attributedText = atts;
    if (_model.type.integerValue == 2) {
        _goodsAllPriceView.valueLabel.text = [NSString stringWithFormat:@"%.2f",_model.goodsprice.doubleValue];
        NSString *string = _goodsAllPriceView.valueLabel.text;
        NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string];
        [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(0,  string.length - 3)];
        _goodsAllPriceView.valueLabel.attributedText = atts;
    }
    _orderAllPriceView.valueLabel.text = [NSString stringWithFormat:@"￥%.2f",_model.goodsprice.doubleValue];
    NSString *string2 = _orderAllPriceView.valueLabel.text;
    NSMutableAttributedString *atts2 = [[NSMutableAttributedString alloc] initWithString:string2];
    [atts2 setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(1,  string2.length - 4)];
    _orderAllPriceView.valueLabel.attributedText = atts2;
    if (_model.type.integerValue == 2) {
        _orderAllPriceView.valueLabel.text = [NSString stringWithFormat:@"%.2f",_model.goodsprice.doubleValue];
        NSString *string2 = _orderAllPriceView.valueLabel.text;
        NSMutableAttributedString *atts2 = [[NSMutableAttributedString alloc] initWithString:string2];
        [atts2 setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(0,  string2.length - 3)];
        _orderAllPriceView.valueLabel.attributedText = atts2;
    }
//    "name":""//收货人姓名
//      "phone":""//收货人电话
//      "address":""//收货地址
    _detailAddressLabel.text = _model.address;
    _userNameLabel.text = [NSString stringWithFormat:@"%@ %@",_model.phone,_model.name];
    _headerMessageLabel.text = _model.statusString;
    _yunfeiView.valueLabel.text = [NSString stringWithFormat:@"%.2f",_model.freight.doubleValue];
    string = _yunfeiView.valueLabel.text;
    atts = [[NSMutableAttributedString alloc] initWithString:string];
    [atts setAttributes:@{NSFontAttributeName:systemBoldFont(TSScaleW(15))} range:NSMakeRange(0,  string.length - 3)];
    _yunfeiView.valueLabel.attributedText = atts;
}
-(void)setAddressModel:(LXAddressModel *)addressModel{
    _addressModel = addressModel;
   
       

}
@end
